-
Notifications
You must be signed in to change notification settings - Fork 104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
separate doc-level monitor query indices for externally defined monitors #1664
Conversation
Signed-off-by: Subhobrata Dey <[email protected]>
@@ -374,6 +374,13 @@ class DocumentLevelMonitorRunner : MonitorRunner() { | |||
// Clean up any queries created by the dry run monitor | |||
monitorCtx.docLevelMonitorQueries!!.deleteDocLevelQueriesOnDryRun(monitorMetadata) | |||
} | |||
|
|||
if (monitor.dataSources.queryIndex.contains("optimized")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
plz add a flag in monitor creation called deleteQueryIndexBeforeEveryRun
(or something briefer)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added as part of pr opensearch-project/common-utils#734
if (monitor.dataSources.queryIndex.contains("optimized")) { | ||
val ack = monitorCtx.docLevelMonitorQueries!!.deleteDocLevelQueryIndex(monitor.dataSources) | ||
if (!ack) { | ||
logger.error("Deletion of concrete queryIndex:${monitor.dataSources.queryIndex} is not ack'd!") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
plz log monitor id
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed it.
@@ -385,6 +392,14 @@ class DocumentLevelMonitorRunner : MonitorRunner() { | |||
RestStatus.INTERNAL_SERVER_ERROR, | |||
e | |||
) | |||
if (monitor.dataSources.queryIndex.contains("optimized") && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
plz dont write this twice
move this to finally block
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed it.
@@ -95,57 +95,69 @@ object DeleteMonitorService : | |||
|
|||
private suspend fun deleteDocLevelMonitorQueriesAndIndices(monitor: Monitor) { | |||
try { | |||
val metadata = MonitorMetadataService.getMetadata(monitor) | |||
metadata?.sourceToQueryIndexMapping?.forEach { (_, queryIndex) -> | |||
if (monitor.owner == "alerting") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
plz delete based on a boolean flag that defaults to false.
This is an anti pattern and makes code unmaintainable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed it based on boolean flag passed from common-utils
.
@@ -537,7 +537,8 @@ class TransportIndexMonitorAction @Inject constructor( | |||
if ( | |||
request.monitor.isMonitorOfStandardType() && | |||
Monitor.MonitorType.valueOf(request.monitor.monitorType.uppercase(Locale.ROOT)) == | |||
Monitor.MonitorType.DOC_LEVEL_MONITOR | |||
Monitor.MonitorType.DOC_LEVEL_MONITOR && | |||
request.monitor.owner == "alerting" | |||
) { | |||
indexDocLevelMonitorQueries(request.monitor, indexResponse.id, metadata, request.refreshPolicy) | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here source to query mapping is updated but in case of new change query index doesnt even get created and wrong value would come up right?
this needs to be handled too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the source to query mapping is dynamically updated during the first monitor run as shown in this logic. https://github.com/opensearch-project/alerting/blob/main/alerting/src/main/kotlin/org/opensearch/alerting/util/DocLevelMonitorQueries.kt#L481
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this method being called for the monitors with dedicated queryindex also?
https://github.com/opensearch-project/alerting/blob/main/alerting/src/main/kotlin/org/opensearch/alerting/util/DocLevelMonitorQueries.kt#L473C25-L473C49
this code snippet will always throw exception right?
targetQueryIndex = getWriteIndexNameForAlias(monitor.dataSources.queryIndex)
if (targetQueryIndex == null) {
val message = "Failed to get write index for queryIndex alias:${monitor.dataSources.queryIndex}"
log.error(message)
throw AlertingException.wrap(
OpenSearchStatusException(message, RestStatus.INTERNAL_SERVER_ERROR)
)
}
because the queryIndex is not an alias anymore?
.execute(it) | ||
} | ||
} | ||
if (currentMonitor.owner == "alerting") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
refactor to use flag
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed it.
@@ -181,6 +182,16 @@ class DocLevelMonitorQueries(private val client: Client, private val clusterServ | |||
} | |||
} | |||
|
|||
suspend fun deleteDocLevelQueryIndex(dataSources: DataSources): Boolean { | |||
val ack: AcknowledgedResponse = client.suspendUntil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we do exists check before deleting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
plz remove request.monitor.owner == "alerting"
and replace with a flag from monitor creation that defaults to false.
Boolean flag should determine if query index should be deleted in every run
Signed-off-by: Subhobrata Dey <[email protected]>
hi @eirsep , removed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
scheduled jobs json mapping needs to be updated
Signed-off-by: Subhobrata Dey <[email protected]>
fixed this. |
Signed-off-by: Subhobrata Dey <[email protected]>
@@ -537,7 +537,8 @@ class TransportIndexMonitorAction @Inject constructor( | |||
if ( | |||
request.monitor.isMonitorOfStandardType() && | |||
Monitor.MonitorType.valueOf(request.monitor.monitorType.uppercase(Locale.ROOT)) == | |||
Monitor.MonitorType.DOC_LEVEL_MONITOR | |||
Monitor.MonitorType.DOC_LEVEL_MONITOR && | |||
request.monitor.owner == "alerting" | |||
) { | |||
indexDocLevelMonitorQueries(request.monitor, indexResponse.id, metadata, request.refreshPolicy) | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this method being called for the monitors with dedicated queryindex also?
https://github.com/opensearch-project/alerting/blob/main/alerting/src/main/kotlin/org/opensearch/alerting/util/DocLevelMonitorQueries.kt#L473C25-L473C49
this code snippet will always throw exception right?
targetQueryIndex = getWriteIndexNameForAlias(monitor.dataSources.queryIndex)
if (targetQueryIndex == null) {
val message = "Failed to get write index for queryIndex alias:${monitor.dataSources.queryIndex}"
log.error(message)
throw AlertingException.wrap(
OpenSearchStatusException(message, RestStatus.INTERNAL_SERVER_ERROR)
)
}
because the queryIndex is not an alias anymore?
@@ -711,7 +711,7 @@ class TransportIndexMonitorAction @Inject constructor( | |||
.execute(it) | |||
} | |||
} | |||
if (currentMonitor.owner == "alerting") { | |||
if (currentMonitor.deleteQueryIndexInEveryRun == false) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alerting/alerting/src/main/kotlin/org/opensearch/alerting/util/DocLevelMonitorQueries.kt
Line 459 in b280761
log.debug(bulkItemResponse.failureMessage) |
plz change it to error log
triggers = listOf(trigger) | ||
triggers = listOf(trigger), | ||
dataSources = DataSources(), | ||
owner = "alerting" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
plz add 2 new tests-
- scenario where delete query index flag is false and monitor execution fails due to mapping conflict on alias rollover
- scenario where delete query index flag is true and monitor execution succeeds
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in first test plz also update monitor with flag false to true and do rollover again and this time assert monitor execution succeeeds
#1664 (comment) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
follow up PR with tests menttioned and error message
…ors (#1664) Signed-off-by: Subhobrata Dey <[email protected]> (cherry picked from commit abdeca9) Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
…ors (#1664) Signed-off-by: Subhobrata Dey <[email protected]> (cherry picked from commit abdeca9) Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
…ors (#1664) Signed-off-by: Subhobrata Dey <[email protected]> (cherry picked from commit abdeca9) Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
…ors (#1664) (#1667) Signed-off-by: Subhobrata Dey <[email protected]>
…ors (#1664) Signed-off-by: Subhobrata Dey <[email protected]> (cherry picked from commit abdeca9) Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
…ors (opensearch-project#1664) (opensearch-project#1667) Signed-off-by: Subhobrata Dey <[email protected]>
Description
separate doc-level monitor query indices for externally defined monitors
Adds boolean flag in monitor config to
deleteQueryIndexInEveryRun
Related Issues
Resolves #[Issue number to be closed when this PR is merged]
Check List
--signoff
.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.